import { request } from '../utils/request'
import type { ImageTask, ApiResponse, PaginatedResponse } from '../types'

// 上传图片
export const uploadImageApi = (file: File, onUploadProgress?: (progressEvent: any) => void) => {
  const formData = new FormData()
  formData.append('file', file)
  
  return request.upload<ApiResponse<{ file_url: string; filename: string }>>(
    '/image/upload', 
    formData, 
    onUploadProgress
  )
}

// 生成图片
export const generateImageApi = (data: {
  original_image_url: string
  style_template_id: number
  custom_prompt?: string
}) => {
  return request.post<ApiResponse<{ task_id: string; task: ImageTask }>>('/image/generate', data)
}

// 获取任务状态
export const getTaskStatusApi = (taskId: string) => {
  return request.get<ApiResponse<{ task: ImageTask }>>(`/image/task/${taskId}`)
}

// 获取生成历史
export const getHistoryApi = (page = 1, perPage = 10) => {
  return request.get<ApiResponse<PaginatedResponse<ImageTask>>>('/image/history', {
    params: { page, per_page: perPage }
  })
}